<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php  session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title></title>
</head>

<body>

	<?php
    	include("connectdb.php");
		
		if($_POST["code"]){
			$code = $_POST["code"];
			
			if($code == $_SESSION["verify_value"]){
				$username = $_POST["username"];
				$pwd = $_POST["pwd"];
				$repwd = $_POST["repwd"];
				$name = $_POST["name"];
				$surname = $_POST["surname"];
				$question = $_POST["question"];
				$answer = $_POST["answer"];
				$type = 3;
				$status = 0;
				
				$sqlq = "Select * from member where memusername='".$username ."'";
				$resultq = mysql_query($sqlq);
				$row = mysql_num_rows($resultq);
				
				if($row == 1){
					?>
						<script language="javascript">
							alert("ชื่อผู้ใช้ซ้ำค่ะ");
						</script>
					<?
				}
				else{
					if($pwd == $repwd){
						$sql = "Insert into member values(NULL,'".$username ."',MD5('".$pwd ."'),'".$name ."','".$surname ."','".$question ."','".$answer ."',".$type .",".$status .");";
					 	mysql_query("SET NAMES 'tis620' ");
						$result = mysql_query($sql);
					}
					else{
						?><meta http-equiv="refresh" content="0;url=register.php"><?
					}
				}
				
				
			}
			else{
				?>
					<script language="javascript">
						alert("รหัสรักษาความปลอดภัยไม่ถูกต้องค่ะ");
					</script>
				<?
			}
		}
		
	?>
    
    <meta http-equiv="refresh" content="0;url=register.php">

</body>
</html>